package com.ruoyi.project.config;

import com.ruoyi.project.constant.MqConstants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author hry
 * 声明交换机、队列、通过路由键绑定交换机和队列
 **/
@Configuration
public class RabbitMQConfig {

    @Bean("test_exchange")
    public Exchange testExchange(){
        return ExchangeBuilder.topicExchange(MqConstants.TEST_EXCHANGE).durable(true).build();
    }
    @Bean("test_queue")
    public Queue testQueue(){
        return QueueBuilder.durable(MqConstants.TEST_QUEUE).build();
    }

    @Bean
    public Binding testQueueExchange(@Qualifier("test_queue") Queue queue,
                                     @Qualifier("test_exchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(MqConstants.TEST_KEY).noargs();
    }
}
